from django.db import models


class AdminLog(models.Model):
    ACTION_CHOICES = (
        ('create', '创建'),
        ('update', '更新'),
        ('delete', '删除'),
        ('approve', '审核'),
        ('reject', '拒绝'),
    )

    admin_user = models.ForeignKey('accounts.User', on_delete=models.CASCADE, related_name='admin_logs')
    action = models.CharField(max_length=20, choices=ACTION_CHOICES, verbose_name='操作类型')
    model_name = models.CharField(max_length=50, verbose_name='模型名称')
    object_id = models.IntegerField(verbose_name='对象ID')
    description = models.TextField(verbose_name='操作描述')
    ip_address = models.GenericIPAddressField(verbose_name='IP地址')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    class Meta:
        db_table = 'admin_log'
        verbose_name = '管理员操作日志'
        verbose_name_plural = verbose_name
        ordering = ['-created_at']

    def __str__(self):
        return f"{self.admin_user.username} - {self.action} {self.model_name}"
